package cn.bby.tools.utils;

import cn.hutool.core.codec.Base64;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.core.util.ZipUtil;
import org.eclipse.jgit.util.Base85;

import javax.sound.midi.Soundbank;
import javax.swing.*;
import java.awt.image.BufferedImage;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author ben
 * @since 2025/9/24 22:43
 */
public class SimpleStringUtil {
    public static String toSmallCamel(List<String> words) {
        return StrUtil.lowerFirst(toBigCamel(words));
    }

    public static String toBigCamel(List<String> words) {
        return words.stream()
                .map(String::toLowerCase)
                .map(StrUtil::upperFirst)
                .collect(Collectors.joining(""));
    }

    public static String toUnderlineLower(List<String> words) {
        return words.stream()
                .map(String::toLowerCase)
                .collect(Collectors.joining("_"));
    }

    public static String toUnderlineUpper(List<String> words) {
        return words.stream()
                .map(String::toUpperCase)
                .collect(Collectors.joining("_"));
    }

    public static String toWord(List<String> words) {
        return words.stream()
                .map(String::toLowerCase)
                .collect(Collectors.joining(" "));
    }

    /**
     * 压缩字符串
     */
    public static String compress(String str) {
        byte[] zlib = ZipUtil.zlib(str, "UTF-8", 1);
        return Base64.encode(zlib);
    }

    public static void main(String[] args) {
        String str = FileUtil.readString("D:\\projects\\FastDevTools\\src\\main\\java\\cn\\bby\\tools\\utils\\StringImageUtil.java", StandardCharsets.UTF_8);
//
//        String str = "";
        str= str.substring(8000);
        String res = ByteStringUtil.compressMinimize(str);
        System.out.println(str.length());
        System.out.println(res.length());
        System.out.println(ByteStringUtil.decompressMinimize(res).equals(str));
        BufferedImage encode = StringImageUtil.encode(res);
        List<StringImageUtil.DecodeResult> decodeResults = StringImageUtil.decodeMultiple(encode);
        char[] charArray = decodeResults.get(0).text().toCharArray();
        for (int i = 0; i < charArray.length; i++) {
            if (res.charAt(i)!= charArray[i]){
                System.out.println((((int) res.charAt(i))+ "-" + ((int) charArray[i])));
            }
        }
        System.out.println(str.equals(ByteStringUtil.decompressMinimize(decodeResults.get(0).text())));
    }
}
